package my.mybatis.common.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:wangbin.
 * @Description.
 * @Date:Created in 10:41 2017/9/18.
 * @Modified By:
 */
@ApiModel(description = "特殊查询operator枚举值")
public class OperatorConventor {
	@ApiModelProperty(value = "相等")
    public static final String EQ = "eq";                // =
	@ApiModelProperty(value = "大于")
    public static final String GT = "gt";                // >
	@ApiModelProperty(value = "大于等于")
    public static final String GE = "ge";                // >=
	@ApiModelProperty(value = "小于")
    public static final String LT = "lt";                // <
	@ApiModelProperty(value = "小于等于")
    public static final String LE = "le";                // <=
	@ApiModelProperty(value = "模糊查询：like")
    public static final String LIKE = "like";            // like
	@ApiModelProperty(value = "模糊查询：notLike")
    public static final String NOTLIKE = "notlike";      // not like
    @ApiModelProperty(value = "不相等")
    public static final String NE = "ne";                // <>
    @ApiModelProperty(value = "为空")
    public static final String ISNULL = "isnull";        // is null
    @ApiModelProperty(value = "不为空")
    public static final String ISNOTNULL = "isnotnull";  //is not null
    @ApiModelProperty(value = "在之间")
    public static final String IN = "in";                // in
    @ApiModelProperty(value = "不在之间")
    public static final String NOTIN = "notin";          // not in

    private static final Map<String,String> map;
    static {
        map = new HashMap<String,String>();
        map.put(EQ," = ");
        map.put(GT," > ");
        map.put(GE," >= ");
        map.put(LT," < ");
        map.put(LE," <= ");
        map.put(LIKE," like ");
        map.put(NOTLIKE," not like ");
        map.put(NE," <> ");
        map.put(ISNULL," is null ");
        map.put(ISNOTNULL," is not null ");
        map.put(IN," in ");
        map.put(NOTIN," not in ");
    }

    public static String get(String operation)
    {
        String converOperation = map.get(operation);
        return StringUtils.isEmpty(converOperation) ? "=" : converOperation;
    }

    private OperatorConventor(){}

    private static class InnerClass
    {
        private static final OperatorConventor SERACH_PARAM_OPERATION_CONVERSION = new OperatorConventor();
    }

    public static OperatorConventor getInstance()
    {
        return InnerClass.SERACH_PARAM_OPERATION_CONVERSION;
    }
}
